<?php


namespace App\Repositories\Lottery;

use App\Traits\Singleton;
use App\Models\MainDB\Lottery\PoolPrize as Model;

class PrizeRepository
{
    use Singleton;

    public function show(array $filters = [])
    {
        $prizes = $this->prizes($filters);
        return $prizes->transform(function ($item) {
            $item->price = $item->gift->price;
            return $item;
        })->sortByDesc('price');
    }

    public function prizes(array $filters = [])
    {
        $query = Model::query();
        $query->where($filters);
        $query->with(['gift']);
        return $query->get()->unique('prize_id');
    }

    public function all(array $condition = [])
    {
        $query = Model::query();
        $query->where($condition);
        $query->with(['gift']);
        $models = $query->get();
        return $models;
    }
}